package com.education.ai.repository;

import com.education.ai.entity.AbilityAssessment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 能力评估资源库接口
 */
@Repository
public interface AbilityAssessmentRepository extends JpaRepository<AbilityAssessment, Long> {
    
    /**
     * 根据学生ID查找能力评估
     */
    List<AbilityAssessment> findByStudentId(String studentId);
    
    /**
     * 根据学科查找能力评估
     */
    List<AbilityAssessment> findBySubject(String subject);
    
    /**
     * 根据学生ID和学科查找能力评估
     */
    List<AbilityAssessment> findByStudentIdAndSubject(String studentId, String subject);
    
    /**
     * 查找学生在某学科的最新评估
     */
    List<AbilityAssessment> findByStudentIdAndSubjectOrderByAssessmentTimeDesc(String studentId, String subject);
    
    /**
     * 查找学生在某学科的最新评估（获取第一条记录）
     */
    AbilityAssessment findFirstByStudentIdAndSubjectOrderByAssessmentTimeDesc(String studentId, String subject);
    
    /**
     * 统计各维度的平均分
     */
    @Query("SELECT AVG(a.knowledgeDimension), AVG(a.applicationDimension), AVG(a.innovationDimension) FROM AbilityAssessment a WHERE a.subject = ?1")
    Object[] getAverageScoresBySubject(String subject);
} 